package variasIteraciones;

import javax.imageio.ImageIO;

import ij.ImagePlus;
import hips.Image;
import hips.Partition;
import hips.Region;

public class Main {

	public static void main(String[] args) {
		try {
			ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
			ImagePlus bmw = new ImagePlus("BMW", ImageIO.read(classLoader.getResourceAsStream("bmw.jpg")));
			processImage(bmw);
		} catch (Exception e) {}
	}

	static int ITERACIONES = 6;
	
	public static void processImage(ImagePlus impl){
		Image img = Image.getImage(impl);
		Partition p = img.newPartition(Partition.IMPROVED_WITHOUT_CINDEX, img.newPixelValue(50), img.newPixelValue(100), 0, 10);
    	System.out.println("Imagen: " + impl.getTitle());

		for (int i = 0; i < ITERACIONES; i++){
			p.makeRegions();
			System.out.println("Iteración: " + i);
			System.out.println("Numero de regiones: " + p.getRegionSize());
			System.out.println("");
			for (int j = 0; j < p.getRegionSize(); j++) {
				Region region = p.getRegionByLabel(j);
				img.paintRegion(region, img.getMeanValue(region));
			}
		}
	}
	
}
